package com.pzhu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pzhu.model.entity.Thali;
import com.pzhu.model.vo.ThaliCountVo;
import com.pzhu.model.vo.ThaliMoneyVo;
import com.pzhu.model.vo.ThaliTreeVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author : zqh
 * @Date : 2023/12/3 0003 下午 4:59
 * @Version: 1.0
 */
public interface ThaliMapper extends BaseMapper<Thali> {

    ThaliTreeVo findAllByTree(Integer parentId);

    @Select("SELECT t.*, c.name as career_name, tc.career_id\n" +
            "FROM `hs_thali` t \n" +
            "LEFT JOIN `hs_thali_career` tc ON t.id = tc.thali_id \n" +
            "LEFT JOIN `hs_career` c ON tc.career_id = c.id;")
    List<ThaliTreeVo> selectInfo();

    @Select("SELECT s.name,sum(o.total_amount) as sum from hs_thali s LEFT JOIN hs_order o ON s.id = o.thali_id\n" +
            "WHERE parent_id > 0\n" +
            "GROUP BY s.name")
    List<ThaliMoneyVo> thaliMoney();

    @Select("SELECT id,name FROM hs_thali WHERE parent_id = 1")
    List<ThaliCountVo> thaliBigCount();

    List<ThaliCountVo> thaliCount(Integer status);
}
